package exception;

import java.util.Scanner;

public class IntegerInputTest {
	
	public int readInt() {
		
		try {
			Scanner sc = new Scanner(System.in);
			System.out.print("숫자를 입력하세요: ");
			String s = sc.nextLine();
			int i = Integer.parseInt(s);
			sc.close();
			return i;
		} catch (NumberFormatException e) {
			return Integer.MIN_VALUE;
		}
	}
	
	public static void main(String[] args) {
		
		IntegerInputTest test = new IntegerInputTest();
		
		int a = 0;
		while (true) {
			try {
				a = test.readInt();
				break;
			} catch (NumberFormatException e) {
				System.out.println("예외 발생! 다시입력하세요.");
			}
		}
		
		System.out.println("입력한 숫자는: " + a);
		
	}
	
}
